/**
 * 
 */
package io.dora.zk;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

/**
 * @author zhaohongbo
 *
 */
public class ZkNodeWatcher implements Watcher {
	
	private ZooKeeper zk;
	private String node;
	
	public ZkNodeWatcher(ZooKeeper zk, String node) {
		this.zk = zk;
		this.node = node;
	}
	
	public void process(WatchedEvent event) {
		System.out.println(event.toString());
		System.out.println("------------------>");
		System.out.println("data change");
		System.out.println(event.getPath());
		try {
			System.out.println("new data:" + new String(zk.getData("/jshop-cx/com.jd.jshop.rpc.face.HelloRpc", false, null)));
			zk.getData(node, this, null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
